set mem 500m
set more off
*Create datasets to save the results 
clear
set obs 1
gen b1=.
gen b2=.
gen b3=.
gen nobs=.
gen sigma=.
gen trial=.
gen rsq=.
save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample11
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample11.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1000+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample12
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample12.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1100+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample13
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample13.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1200+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample14
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample14.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1300+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample15
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample15.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1400+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample16
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample16.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1500+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample17
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample17.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1600+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample18
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample18.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1700+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample19
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample19.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1800+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

*OLS_sample20
clear 
foreach i of num 1/100{
use "C:\OLS_simulation2\sample20.dta"
qui reg y`i' x`i' z`i' if y`i'>0
drop _all
matrix b=get(_b)
capture svmat b
gen sigma = e(rmse)
gen nobs = e(N)
gen trial = 1900+`i'
gen rsq = e(r2)
capture append using "C:\OLS_simulation2\ols_result2.dta"
capture save "C:\OLS_simulation2\ols_result2.dta", replace
}
sort trial
capture save "C:\OLS_simulation2\ols_result2.dta", replace

